/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mx.its.dsw2.Bl;

import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import mx.its.dsw2.Enumerations.TransactionStatus;
import mx.itsc.ds2.Dao.StudentDaoLocal;
import mx.itsc.ds2.model.Student;

/**
 *
 * @author Juan Carlos
 */
@Stateless
public class StudensBL implements StudensBLLocal {

    @EJB
    private StudentDaoLocal studentDao;

    @Override
    public TransactionStatus register(Student student) {
        if (studentDao.findDuplicity(student)) {
            return TransactionStatus.INCOMPLETO;
        } else {
            studentDao.create(student);
            return TransactionStatus.COMPLETO;
        }
    }

    @Override
    public TransactionStatus delete(Student student) {
        if (student.getId() == null || studentDao.find(student.getId())== null) {
            return TransactionStatus.INCOMPLETO;
        } else {
            studentDao.remove(student);
            return TransactionStatus.COMPLETO;
        }
    }

    @Override
    public TransactionStatus modify(Student student) {
        if (student.getId() == null || studentDao.find(student.getId())== null) {
            return TransactionStatus.INCOMPLETO;
        } else {
            studentDao.edit(student);
            return TransactionStatus.COMPLETO;
        }
    }

    @Override
    public List<Student> listAll() {
        return studentDao.findAll();
    }

    @Override
    public Student findById(int idStudent) {
        return studentDao.find(idStudent);
    }
    
    
}
